<?php
error_reporting(0);
require_once "./lib.php";

if (!empty($_SERVER["REQUEST_URI"])) {
	$filename = empty($_SERVER["SCRIPT_FILENAME"]) ? "proxy.php" : $_SERVER["SCRIPT_FILENAME"];
	if (preg_match('/[^\/]+$/', $filename, $matches)) {
		$filename = $matches[0];
	}
	$url = $_SERVER["REQUEST_URI"];
	$url = preg_replace('/^[\s\S]+' . $filename . '\//', "", $url);
	if (!preg_match('/^https?:\/\//', $url)) {
		if (preg_match('/:443/', $url)) {
			$url = "https://" . $url;
		} else {
			$url = "http://" . $url;
		}
	}
	proxy($url);
}
// proxy("https://www.baidu.com:443/");